'use strict';

angular.module('mean.employ')
    //企业用户根Controller
    .controller('CompanyMainController', function($scope, $http) {
        $scope.companyData = {
            //companyInfo  企业基本信息
            //postJob      发布职位
        };

        $scope.refreshCompanyData = function() {
            return $http.get('/wx/employ/companyInfo').then(function(success) {
                $scope.companyData.companyInfo = success.data;
                return $http.get('/wx/employ/postJob', {
                    params: {companyId: $scope.companyData.companyInfo._id}
                });
            }).then(function(success) {
                $scope.companyData.postJob = success.data;
            });
        };
        $scope.refreshCompanyData();
    })
    .controller('CompanyIndexController', function($scope, $state) {
        $scope.companyInfo = function() {
            $state.go('company.info');
            
        };
        $scope.postJobList = function() {
            $state.go('company.postJobList');
        };
    
     
    })
    .controller('CompanyInfoController', function($scope, $state) {
        $scope.edit = function() {
            $state.go('company.editInfo');
        };
        $scope.$watch('companyData.companyInfo.status', function() {
            if($scope.companyData.companyInfo.status === 0) {$scope.status = '审核中';}
            if($scope.companyData.companyInfo.status === 1) {$scope.status = '已审核';}
            if($scope.companyData.companyInfo.status === 2) {$scope.status = '审核不通过';}
        });
    })
    .controller('CompanyEditInfoController', function($scope, $state, $http) {
        $scope.save = function() {
            return $http.put('/wx/employ/companyInfo', {
                companyInfo: $scope.companyData.companyInfo
            }).then(function(success) {
                return $scope.refreshCompanyData();
            }).then(function() {
                $state.go('company.info');
            });
        };
    })
    .controller('PostJobListController', function($scope,$state) {
         
   
    })

;